<?php
/**
 * Created by 上海互教教育科技有限公司.
 * User: 刘红伟
 * QQ  : 454303753
 * Date: 2017/5/31 0031
 * Time: 下午 15:31
 */
namespace  App\Http\Controllers\v1;
use App\Service;
use App\Set_conf;
use Illuminate\Http\Request;

use Laravel\Lumen\Routing\Controller as BaseController;

class ServiceController extends BaseController
{

    public function add(Request $request)
    {

        if($request)
        {

            $service_obj  =  new Service();
            $service_obj->item_name            =   $request->item_name;
            $service_obj->item_time       =   time();
            $service_obj->create_at       =   time();
            if($service_obj->save())
            {
                return response()->json(array('status'=>1),200);
            };

            return response()->json(array('status'=>0),200);

        }


    }


    public function get_data(Request $request)
    {
        $item_id = $request->item_id;
        $services =   Service::find($item_id);

        if($services)
        {
            return response()->json($services,200);
        }else
        {
            return response()->json((object)array(),200);
        }

    }

    public function get_all()
    {
        $services =   Service::all();

        if($services){
            return response()->json( $services , 200 );
        }else
        {
            return response()->json((object)array(),200);
        }

    }

    public function get_conf(){
        $data   =   [];
        $confs  =   Set_conf::all();
        if($confs)
        {
            foreach($confs as $v)
            {
                $data[$v->column_name]  =   $v->column_value;
            }
            return response()->json($data,200);
        }else
        {
            return response()->json((object)array(),200);
        }
    }



}